<template>
  <div id="box">
    <div class="content">
        <h3>嗨购管理系统</h3>
      <el-form
        ref="ruleFormRef"
        style="max-width: 600px"
       
        status-icon
       
        label-width="auto"
        class="demo-ruleForm"
      >
    
    <el-input
      v-model="admin"
      style="width: 240px"
      size="large"
      placeholder="Please Input"
      :prefix-icon="UserFilled"
    />
   
        <el-form-item >
          <el-input type="password" placeholder="管理员密码" v-model="pass":prefix-icon="UserFilled"style="width: 240px"size="large"/>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="login()"> 登录 </el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script lang="ts" setup>
import { UserFilled } from "@element-plus/icons-vue";
import { reactive, ref } from "vue";
import router from "@/router";
import { doLogin } from "@/apis/index";
import { useUserStore } from "@/stores/user";
const useUser=useUserStore()
const admin=ref<string>("admin")
const pass=ref<string>("123456")
const login=()=>{
    doLogin({
          adminname:admin.value,
    password:pass.value
}).then(res=>{
    console.log(res);
    if(res.data.code==200){
      useUser.changeToken(res.data.data.token)//实现自动存储token
      useUser.changeAdminid(res.data.data.adminid)
        console.log(res);
        router.push("/home")
    }else{
        alert("账号或者密码错误重新登录")
    }
}).catch(error=>{
    console.error("登入失败",error)
    alert("登录失败，请重试")
    
})
}
    
  console.log(useUser.token);
  console.log(useUser.adminid);

</script>

<style>
body,html,#app{
    height:100%;
}
#box{
    height: 100%;
    background-color: blueviolet;
    display: flex;
    justify-content: center;
    align-items: center;
}
.content{
    text-align: center;
}
.el-button{
    margin: 0 auto;
}



</style>
